AddCSLuaFile( "cl_init.lua" ) // Make sure clientside  
AddCSLuaFile( "shared.lua" )  // and shared scripts are sent.     
include('shared.lua')     

function ENT:Initialize()     	
	self.Entity:SetModel( "models/props_lab/servers.mdl" )  	
	self.Entity:PhysicsInit( SOLID_VPHYSICS )      // Make us work with physics,  	
	self.Entity:SetMoveType( MOVETYPE_VPHYSICS )   // after all, gmod is a physics  	
	self.Entity:SetSolid( SOLID_VPHYSICS )         // Toolbox                
	local phys = self.Entity:GetPhysicsObject()  	
	if (phys:IsValid()) then  		
		phys:Wake()  	
	end  
	self.on = true
	self.enabled = true
	self.used = false
end     

 function ENT:Update(pos)
 t = {}
 local r = pos + 1
 if (pos < self.count) then
 t.pos = self.buffer[r].pos
 t.current = r
  t.speed = self.buffer[r].speed
   t.lp = self.buffer[r].lp
    t.dr = self.buffer[r].dr
 else
 t.pos = self.buffer[1].pos
 t.current = 1
  t.speed = self.buffer[1].speed
  t.lp = self.buffer[1].lp
  t.dr = self.buffer[1].dr
 end
 return t
 end
 
 function ENT:Use(activator)
 if (!self.used) then
self.used = true
timer.Simple(1,unuse,self)
if (self.on) then
for k,v in pairs(self.ents) do
v:Remove()
end
self.ents = {}
self.on = false
self.enabled = false
else
for k,v in pairs(self.buffer) do
            local conveyor = ents.Create( "conventpad" )
			conveyor:SetAngles(Angle(90,0,0))
			conveyor:Spawn()
			local g = self:Update(k)
			local r = g.pos
			r.z = r.z + 1
			conveyor.pos = r
			conveyor:SetPos( g.pos )
			conveyor.speed = g.speed
			conveyor.control = self.Entity
			conveyor.current = g.current
			conveyor.lp = t.lp
			conveyor.dr = t.dr
			conveyor.on = true
			local p = conveyor:GetPhysicsObject()
			p:Wake()
			p:EnableGravity( false )
			self.Entity:DeleteOnRemove(conveyor)
			table.insert(self.ents,conveyor)
		end
self.on = true
end
end
end
 
 function unuse(self)
 self.used = false
 end
 

 